<?php
/**
 * Joomla! 1.5 component ArticleCashRewards
 *
 * @version $Id: mypage.php 2009-05-10 01:47:01 svn $
 * @author Maverick
 * @package Joomla
 * @subpackage components.controllers
 * @link http://joomladev.boddunan.com
 * @license GNU/GPL
 *
 * Review and approve the articles and assign points and cash rewards.
 * Users can see their articles and the points/cash rewards assigned in the front-end module.
 */
 
// No direct access
 
defined( '_JEXEC' ) or die( 'Restricted access' );
 
jimport('joomla.application.component.controller');
 
/**
 * Articles Cash Rewards Component Articles Controller
 *
 * @package    Joomla.Tutorials
 * @subpackage Components
 */
class ArticleCashRewardsControllerMypage extends JController
{

	function __construct(){
		parent::__construct();
        
        global $mainframe, $acr_config;
        $acr_config = $mainframe->getUserState( SESSION_ACR_CONFIG );
        if(!isset($acr_config)){
            $model = & $this->getModel('config');
            $configt = $model->getConfiguration();

            foreach($configt as $ct){
                $acr_config[$ct->config_name] = $ct->config_value;
            }
            $mainframe->setUserState( SESSION_ACR_CONFIG, $acr_config );
        }
        
        $this->registerTask( 'dashboard','getDashBoard' );
        $this->registerTask( 'articles','myarticles' );
        $this->registerTask( 'profile','myprofile' );
        $this->registerTask( 'weblinks','myWebLinks' );
        $this->registerTask( 'referrals','myReferrals' );
        $this->registerTask( 'saveprofile','saveProfile' );
        $this->registerTask( 'submitweblink','saveWeblink' );
	}

    function getDashboard(){
        $view = & $this->getView('mypage', 'html');
		$model = & $this->getModel('mypage');
		$view->setModel($model, true);
        $view->setLayout('myprofile');
        $view->display();
    }

    function myArticles(){
        $view = & $this->getView('mypage', 'html');
		$model = & $this->getModel('mypage');
		$view->setModel($model, true);
        $view->setLayout('articles');
        $view->display();
    }

    function myWebLinks(){
        $view = & $this->getView('mypage', 'html');
		$model = & $this->getModel('mypage');
		$view->setModel($model, true);
        $view->setLayout('weblinks');
        $view->display();
    }

    function myReferrals(){
        $view = & $this->getView('mypage', 'html');
		$model = & $this->getModel('mypage');
		$view->setModel($model, true);
        $view->setLayout('referrals');
        $view->display();
    }
    
    function myProfile(){
        $view = & $this->getView('mypage', 'html');
		$model = & $this->getModel('mypage');
		$view->setModel($model, true);
        $view->setLayout('paymentinfo');
        $view->display();
    }

    function saveWebLink(){
        $view = & $this->getView('mypage', 'html');
		$model = & $this->getModel('mypage');

        if($model->saveWebLink()){
            $msg = JText::_("INFO_WEBLINK_SUCCESS");
        }else{
            $msg = JText::_("INFO_WEBLINK_FAILED");
        }
        $view = & $this->getView('mypage', 'html');
		$model = & $this->getModel('mypage');
		$view->setModel($model, true);
        $view->setLayout('weblinks');
        $view->display();
        //$this->setRedirect('index.php?option=com_articlecashrewards&controller=mypage&task=weblinks', $msg);
    }

    function saveProfile(){
        $view = & $this->getView('mypage', 'html');
		$model = & $this->getModel('mypage');

        if($model->saveProfile()){
            $msg = JText::_("INFO_PROFILE_SUCCESS");
        }else{
            $msg = JText::_("INFO_PROFILE_FAILED");
        }
		$view->setModel($model, true);
        $view->setLayout('paymentinfo');
        $view->display();
        //$this->setRedirect('index.php?option=com_articlecashrewards&controller=mypage&task=paymentinfo', $msg);
    }
}
